package com.itetchologyandenglish.home.controller.Api;

import com.itetchologyandenglish.home.config.Log;
import com.itetchologyandenglish.home.enetity.Orders;
import com.itetchologyandenglish.home.enetity.Result;
import com.itetchologyandenglish.home.enetity.TotalOrder;
import com.itetchologyandenglish.home.service.TotalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Response;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Api(tags={"统计模块"})
@Controller
@RequestMapping("/total")
public class StatisticsApiController {
    @Resource
    TotalService totalService;
    @ApiOperation("查看订单点击量")
    @Log("统计分析-查看订单点击量")
    @RequestMapping("/totalOrderClick")
    @ResponseBody
    public Result<Map<String, Integer>> totalOrderClick() {
        Map<String, Integer> map = totalService.totalOrderClick();
        return new Result<Map<String, Integer>>(200, "success", map);
    }
    @ApiOperation("查看订单点击量前几个")
    @Log("统计分析-查看订单点击量前几个")
    @RequestMapping("/getTopClick")
    @ResponseBody
    public Result <List<List<Orders>>> getTopClick(Integer n) {
        List<List<Orders>> ordersAll=new ArrayList<>();
        //1.采购 2.供应
        List<Orders> orders1=totalService.getTopClick(n,1);
        List<Orders> orders2=totalService.getTopClick(n,2);
        ordersAll.add(orders1);
        ordersAll.add(orders2);
        return new Result <List<List<Orders>>>(200, "success", ordersAll);
    }
    @ApiOperation("查看订单点击量图表")
    @Log("统计分析-查看订单点击量图表")
    @RequestMapping("/totalOrder")
    @ResponseBody
    public Result<Map<String, Integer>> totalOrder() {
        Map<String, Integer> map = totalService.totalOrder();
        return new Result<Map<String, Integer>>(200, "success", map);
    }
    @ApiOperation("查看企业VIP图表及信息")
    @Log("统计分析-查看企业VIP图表及信息")
    @RequestMapping("/totalCompanyByDate")
    @ResponseBody
    public Result<List<List<TotalOrder>>> totalCompanyByDate(Integer year){
        //还没写完
        //还没写完
        if(year==null){
            year= LocalDate.now().getYear();
        }
        //vip
        List<TotalOrder> list1=totalService.totalCompanyByDate(year,1);
        System.out.println(list1.toString());
        //非vip
        List<TotalOrder> list2=totalService.totalCompanyByDate(year,0);
        List<List<TotalOrder>> listAll=new ArrayList<>();
        listAll.add(list1);
        listAll.add(list2);
        return new Result<List<List<TotalOrder>>>(200,"success",listAll);
    }
    @ApiOperation("查看订单图表信息")
    @Log("统计分析-查看订单图表信息")
    @RequestMapping("/totalOrderByDate")
    @ResponseBody
    public Result<List<List<TotalOrder>>> totalOrderByDate(Integer year) {
        //查询一年的数据放到这里  1.采购  2.供应   0.未完成  1.完成
        //存放采购订单已经完成的  list1  存放采购订单未完成  list2
        //同上
        if(year==null){
            year= LocalDate.now().getYear();
        }
        System.out.println(year);
        List<TotalOrder> list1=totalService.totalOrderByYear(year,1,1);
        List<TotalOrder> list2=totalService.totalOrderByYear(year,1,0);
        List<TotalOrder> list3=totalService.totalOrderByYear(year,2,1);
        List<TotalOrder> list4=totalService.totalOrderByYear(year,2,0);
        List<List<TotalOrder>> listAll=new ArrayList<>();
        listAll.add(list1);
        listAll.add(list2);
        listAll.add(list3);
        listAll.add(list4);
        return new Result<List<List<TotalOrder>>>(200,"success",listAll);
    }
    @ApiIgnore
    @Log("统计分析-订单年份")
    @RequestMapping("/getYears")
    @ResponseBody
    public Result<List<List<String>>> getYears(){
        List<List<String>> allList=new ArrayList<>();
        //里面装载了订单的年  通过订单查询订单的年限
        List<String> orderYear=totalService.totalOrderYears();
        List<String> companyYear=totalService.totalCompanyYears();
        allList.add(orderYear);
        allList.add(companyYear);
        return new Result<List<List<String>>>(200,"success",allList);
    }
    @ApiOperation("查看企业图表")
    @Log("统计分析-查看企业图表")
    @RequestMapping("/totalCompany")
    @ResponseBody
    public Result<Map<String, Integer>> totalCompany() {
        Map<String, Integer> map = totalService.totalCompany();
        return new Result<Map<String, Integer>>(200, "success", map);
    }


}
